package com.geekbg.zookeeper.distributedqueue;

import lombok.Data;

/**
 * @author pizhihui
 * @date 2023-02-27 20:13
 */
@Data
public class QueueItem implements Comparable<QueueItem>{


    final String str;

    QueueItem(String str) {
        this.str = str;
    }


    @Override
    public int compareTo(QueueItem rhs) {
        if (this == rhs) {
            return 0;
        }

        int val = Integer.parseInt(str);
        int rhsVal = Integer.parseInt(rhs.str);
        int diff = val - rhsVal;
        return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        QueueItem that = (QueueItem) o;

        return str.equals(that.str);

    }

    @Override
    public int hashCode() {
        return str.hashCode();
    }



}
